<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript">

function doStuff()
{
document.write("did stuff!");
}

function sendMessage() {
        document.getElementById("textField").innerHTML="Sending message...";
        safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("hey", "there");
   }

function sendLinks() {

        document.getElementById("textField").innerHTML="Sending links...";
        safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("showLinks", "there");
    }

 function respondToMessage(messageEvent) {
        if(messageEvent.name === "gotIt")
       { document.getElementById("textField").innerHTML=messageEvent.message;}
	}

safari.self.browserWindow.addEventListener("message",respondToMessage,false);

</script>

<title> Hello World! </title>
</head>
<body>
<input type="button" value="Links" onclick="sendMessage()">
<input type="button" value="AddIcon" onclick="sendLinks()">
<span id="textField">...waiting... </span>
 </body>
</html>